package cc.comac.mom.config;

import cc.comac.mom.util.ResultBean;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyControllerConfigAdvice {
    @ResponseBody
    @ExceptionHandler(value = RuntimeException.class)
    public ResultBean runtimeExceptionHandler(RuntimeException ex) {
        ResultBean resultBean = new ResultBean(false);
        ex.printStackTrace();
        resultBean.setErrorMessge(ex.getMessage());
        return resultBean;
    }

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public ResultBean exceptionHandler(Exception ex) {
        ResultBean resultBean = new ResultBean(false);
        resultBean.setErrorMessge(ex.getMessage());
        return resultBean;
    }
}
